﻿Public Class RequiredEntryValidationRule
    Inherits ValidationRule

    Private _strFieldTag As String = String.Empty

    Public Property FieldTag() As String
        Get
            Return _strFieldTag
        End Get
        Set(ByVal Value As String)
            _strFieldTag = value
        End Set
    End Property


    Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As System.Windows.Controls.ValidationResult
        If value Is Nothing OrElse (TypeOf value Is String AndAlso String.IsNullOrEmpty(value.ToString)) Then
            If String.IsNullOrEmpty(_strFieldTag) Then
                Return New ValidationResult(False, "this field requires an entry")
            Else
                Return New ValidationResult(False, String.Concat(_strFieldTag, " is a required field"))
            End If

        Else
            Return ValidationResult.ValidResult
        End If
    End Function

End Class
